import request from '@/utils/request'

/**
 * 评论管理API
 */

// 获取评论列表
export function getCommentList(params) {
  return request({
    url: '/api/comments',
    method: 'get',
    params
  })
}

// 获取评论详情
export function getCommentDetail(id) {
  return request({
    url: `/api/comments/${id}`,
    method: 'get'
  })
}

// 创建评论
export function createComment(data) {
  return request({
    url: '/api/comments',
    method: 'post',
    data
  })
}

// 更新评论
export function updateComment(id, data) {
  return request({
    url: `/api/comments/${id}`,
    method: 'put',
    data
  })
}

// 删除评论
export function deleteComment(id) {
  return request({
    url: `/api/comments/${id}`,
    method: 'delete'
  })
}

// 批量删除评论
export function batchDeleteComments(ids) {
  return request({
    url: '/api/comments/batch',
    method: 'delete',
    data: ids
  })
}

// 获取文章评论列表
export function getCommentsByArticle(articleId) {
  return request({
    url: `/api/comments/article/${articleId}`,
    method: 'get'
  })
}

// 获取用户评论列表
export function getCommentsByUser(userId) {
  return request({
    url: `/api/comments/user/${userId}`,
    method: 'get'
  })
}

// 获取评论统计信息
export function getCommentStats() {
  return request({
    url: '/api/comments/stats',
    method: 'get'
  })
}

// 审核评论
export function auditComment(id, status) {
  return request({
    url: `/api/comments/${id}/audit`,
    method: 'put',
    params: { status }
  })
}

// 点赞评论
export function likeComment(id) {
  return request({
    url: `/api/comments/${id}/like`,
    method: 'put'
  })
}

// 获取评论列表（包含关联信息）
export function getCommentListWithRelations(params) {
  return request({
    url: '/api/comments/relations',
    method: 'get',
    params
  })
}

// 置顶/取消置顶评论
export function toggleCommentTop(id, isTop) {
  return request({
    url: `/api/comments/${id}/top`,
    method: 'put',
    params: { isTop }
  })
}

// 批量审核评论
export function batchAuditComments(ids, status) {
  return request({
    url: '/api/comments/batch/audit',
    method: 'put',
    data: {
      ids: ids,
      status: status
    }
  })
}

// 获取置顶评论
export function getTopComments(articleId, limit = 10) {
  return request({
    url: '/api/comments/top',
    method: 'get',
    params: { articleId, limit }
  })
}

// 举报评论
export function reportComment(id, reason) {
  return request({
    url: `/api/comments/${id}/report`,
    method: 'post',
    data: { reason }
  })
}

// 获取评论举报列表
export function getCommentReports(commentId) {
  return request({
    url: `/api/comments/${commentId}/reports`,
    method: 'get'
  })
}
